home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / timeout.zip / TIMEOUT.C next >
C/C++ Source or Header  |  1991-10-28  |  2KB  |  75 lines

  1. /*----------------------------- Module Header --------------------------------
  2.  * timeout.c - A simple batch file wait utility.
  3.  *
  4.  * Revision History:
  5.  *
  6.  * 26-Aug-1991 Created by Eric Brown, who donates it to the public domain
  7.  *             and as such makes no warrantees nor assumes any liability.
  8.  *
  9.  * 28-Oct-1991 Modified by Hans-Georg Michna, Munich, Germany,
  10.  *             CompuServe: 74776,2361  Internet: 74776.2361@compuserve.com
  11.  *             Changed such that DOS errorlevel is 1 if timeout occurs.
  12.  *             Errorlevel remains 0 if a key is hit. The program can now
  13.  *             be used as a security device, for example to boot into a
  14.  *             BIOS password request if no menu choice is made.
  15.  *--------------------------------------------------------------------------*/
  16.  
  17. #include <stdio.h>
  18. #include <time.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <conio.h>
  22.  
  23. void Usage(void);
  24.  
  25. int main(int argc, char **argv[])
  26. {
  27.     time_t  tWait = 0, tNow = 0L, tEnd = 0L;
  28.  
  29.     if (argc > 1) {
  30.         if ((char)argv[1][0] == (char)'-' || (char)argv[1][0] == (char)'/') {
  31.             Usage();
  32.             return 0;
  33.         }
  34.         tWait = (time_t)atoi((char *)argv[1]);
  35.         if (tWait < 0) {
  36.             tWait = 0;
  37.         }
  38.     }
  39.  
  40.     time(&tNow);
  41.  
  42.     tEnd = tNow + tWait;
  43.  
  44.     printf("Waiting %ld seconds, press a key to continue, CTRL+C to interrupt.",
  45.            tWait);
  46.  
  47.     do {
  48.         if (kbhit()) {
  49.         exit(0);
  50.         }
  51.  
  52.         time(&tNow);
  53.  
  54.     } while (tNow < tEnd);
  55.  
  56.     exit(1);
  57. }
  58.  
  59. void Usage(void)
  60. {
  61.     printf("\n\
  62. TIMEOUT - This utility is similar to the DOS PAUSE command.  However, it\n\
  63.       accepts a timeout parameter to specify a length of wait (in seconds)\n\
  64.       at which time it will continue without a key press. If no key is\n\
  65.       pressed, a DOS errorlevel of 1 is returned.\n\
  66. \n\
  67. Usage -   TIMEOUT ###\n\
  68.       where ### is a decimal number of seconds.\n\
  69. \n\
  70. Written by Eric Brown, Seattle, WA, 16-Sep-1991.\n\
  71. Modified by Hans-Georg Michna, Munich, Germany, 28-Oct-1991.\n");
  72.  
  73.     return;
  74. }
  75.